/*
 * @Author: 0x9DEFA478
 * @Date: 2021-11-24 21:17:52
 * @LastEditTime: 2021-11-29 23:08:10
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "IP_DMA2D.h"
#include "H_ThreadScheduler.h"



const unsigned int IP_DMA2D_CLUT_Gary_Table[]={
  
  0xFF000000,0xFF010101,0xFF020202,0xFF030303,0xFF040404,0xFF050505,0xFF060606,0xFF070707,0xFF080808,0xFF090909,0xFF0A0A0A,0xFF0B0B0B,0xFF0C0C0C,0xFF0D0D0D,0xFF0E0E0E,0xFF0F0F0F,
  0xFF101010,0xFF111111,0xFF121212,0xFF131313,0xFF141414,0xFF151515,0xFF161616,0xFF171717,0xFF181818,0xFF191919,0xFF1A1A1A,0xFF1B1B1B,0xFF1C1C1C,0xFF1D1D1D,0xFF1E1E1E,0xFF1F1F1F,
  0xFF202020,0xFF212121,0xFF222222,0xFF232323,0xFF242424,0xFF252525,0xFF262626,0xFF272727,0xFF282828,0xFF292929,0xFF2A2A2A,0xFF2B2B2B,0xFF2C2C2C,0xFF2D2D2D,0xFF2E2E2E,0xFF2F2F2F,
  0xFF303030,0xFF313131,0xFF323232,0xFF333333,0xFF343434,0xFF353535,0xFF363636,0xFF373737,0xFF383838,0xFF393939,0xFF3A3A3A,0xFF3B3B3B,0xFF3C3C3C,0xFF3D3D3D,0xFF3E3E3E,0xFF3F3F3F,
  0xFF404040,0xFF414141,0xFF424242,0xFF434343,0xFF444444,0xFF454545,0xFF464646,0xFF474747,0xFF484848,0xFF494949,0xFF4A4A4A,0xFF4B4B4B,0xFF4C4C4C,0xFF4D4D4D,0xFF4E4E4E,0xFF4F4F4F,
  0xFF505050,0xFF515151,0xFF525252,0xFF535353,0xFF545454,0xFF555555,0xFF565656,0xFF575757,0xFF585858,0xFF595959,0xFF5A5A5A,0xFF5B5B5B,0xFF5C5C5C,0xFF5D5D5D,0xFF5E5E5E,0xFF5F5F5F,
  0xFF606060,0xFF616161,0xFF626262,0xFF636363,0xFF646464,0xFF656565,0xFF666666,0xFF676767,0xFF686868,0xFF696969,0xFF6A6A6A,0xFF6B6B6B,0xFF6C6C6C,0xFF6D6D6D,0xFF6E6E6E,0xFF6F6F6F,
  0xFF707070,0xFF717171,0xFF727272,0xFF737373,0xFF747474,0xFF757575,0xFF767676,0xFF777777,0xFF787878,0xFF797979,0xFF7A7A7A,0xFF7B7B7B,0xFF7C7C7C,0xFF7D7D7D,0xFF7E7E7E,0xFF7F7F7F,
  0xFF808080,0xFF818181,0xFF828282,0xFF838383,0xFF848484,0xFF858585,0xFF868686,0xFF878787,0xFF888888,0xFF898989,0xFF8A8A8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EB,0xFFECECEC,0xFFEDEDED,0xFFEEEEEE,0xFFEFEFEF,
  0xFFF0F0F0,0xFFF1F1F1,0xFFF2F2F2,0xFFF3F3F3,0xFFF4F4F4,0xFFF5F5F5,0xFFF6F6F6,0xFFF7F7F7,0xFFF8F8F8,0xFFF9F9F9,0xFFFAFAFA,0xFFFBFBFB,0xFFFCFCFC,0xFFFDFDFD,0xFFFEFEFE,0xFFFFFFFF,

};



/**
 * @brief 初始化DMA2D
 * @param ip_dma2d IP_DMA2D句柄
 * @param _dma2d dma2d句柄
 * @return 无
 */
void IP_DMA2D_Init(IP_DMA2D* ip_dma2d,DMA2D_TypeDef* _dma2d){

  cIP_DMA2D_DMA2D(ip_dma2d)=_dma2d;

  while((cIP_DMA2D_DMA2D(ip_dma2d)->CR&DMA2D_CR_START)!=0U){
  }
  while((cIP_DMA2D_DMA2D(ip_dma2d)->FGPFCCR&DMA2D_FGPFCCR_START)!=0U){
  }
  while((cIP_DMA2D_DMA2D(ip_dma2d)->BGPFCCR&DMA2D_BGPFCCR_START)!=0U){
  }

  cIP_DMA2D_DMA2D(ip_dma2d)->CR=0U;

  cIP_DMA2D_DMA2D(ip_dma2d)->AMTCR=DMA2D_AMTCR_EN;//启动死区功能

  
  
  ip_dma2d->IsBusy=0;
  ip_dma2d->Result=vIP_DMA2D_Error_None;
  
  ip_dma2d->Sem_OperationDone=new_H_TS_BinarySemaphore();
  if(ip_dma2d->Sem_OperationDone==NULL){
    for(;;){
    }
  }

}

/**
 * @brief 反初始化DMA2D
 * @param ip_dma2d IP_DMA2D句柄
 * @return 0:成功 其他:失败
 */
unsigned int IP_DMA2D_DeInit(IP_DMA2D* ip_dma2d){

  if(ip_dma2d->IsBusy!=0){
    return 0xFFFFFFFFU;
  }

  delete_H_TS_BinarySemaphore(ip_dma2d->Sem_OperationDone);

  return 0U;
}

/**
 * @brief 设置AMTCR
 * @param ip_dma2d IP_DMA2D句柄
 * @param AMTCR AMTCR的值
 * @return 无
 */
void IP_DMA2D_SetAMTCR(IP_DMA2D* ip_dma2d,unsigned int AMTCR){

  cIP_DMA2D_DMA2D(ip_dma2d)->AMTCR=(cIP_DMA2D_DMA2D(ip_dma2d)->AMTCR&(~DMA2D_AMTCR_DT_Msk))|((AMTCR<<DMA2D_AMTCR_DT_Pos)&DMA2D_AMTCR_DT_Msk);

}


